package com.nice.nice201110.controller;

import com.nice.nice201110.entity.TMenu;
import com.nice.nice201110.service.OperationService;
import com.nice.nice201110.vo.MenuVo;
import com.nice.nice201110.vo.TestRequest;
import com.nice.nice201110.vo.UserVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/admin/test")
public class TestController {
    @Autowired
    OperationService operationService;

    Logger logger = LoggerFactory.getLogger(getClass());
    @PostMapping("/update")
    @ResponseBody
    public String update(MultipartFile[] files, @Valid TestRequest trequest, Errors errors) {
        // 这里可以对errors进行处理
        List list = errors.getAllErrors();
        Integer errornum = errors.getErrorCount();
        return list.toString();
    }
    @GetMapping("/log")
    @ResponseBody
    public String log() {
        // 这里可以对errors进行处理
        logger.info("info");
        logger.warn("warn");
        logger.error("error");
        return null;
    }
    @GetMapping("/tMenu")
    @ResponseBody
    public String tMenu() {
        UserVo userVo = new UserVo();
        userVo.setId("28");
        MenuVo menuVo = new MenuVo();
        menuVo.setUservo(userVo);
        List<TMenu> tMenus = operationService.getMenuList(menuVo);
        return tMenus.toString();
    }
}
